
#include "hash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

void print_hash( struct hash_table *sht )
{
	hash_table_iterator iter;
	int count = 0;

	for( hash_table_iterate( sht, &iter ); hash_table_iter_next( &iter );
			++count )
		printf( "%s: %s\n", (const char *)iter.key, (const char *)iter.value );
}

int main( void )
{
	struct hash_table *ht = make_string_hash_table( 0 );
	char line[80];
	int line_n = 0;

	while((fgets( line, sizeof(line), stdin )))	{
		line_n++;
		int len = strlen( line );
		if( len <= 1 )
			continue;
		line[--len] = '\0';
		if( !hash_table_contains( ht, line )) {
			char *value = (char *)malloc( 20 * sizeof(char));
			sprintf( value, "LINENUM: %d", line_n );
			hash_table_put( ht, strdup( line ), value );
		}
#if 1
		if( line_n % 5 == 0 ) {
			char *line_copy, *value_copy;
			if( hash_table_get_pair( ht, line, &line_copy, &value_copy )) {
				hash_table_remove( ht, line );
				free( line_copy );
				free( value_copy );
			}
		}
#endif
	}
#if 1
	print_hash( ht );
#endif

	// TODO : destroy hash table.
	return 0;
}
